package com.example.springbootdemo.controller;

import com.example.springbootdemo.entity.User;
import com.example.springbootdemo.service.UserService;
import com.example.springbootdemo.util.RestListRequest;
import com.example.springbootdemo.util.RestRequest;
import com.example.springbootdemo.util.RestResponse;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    UserService userService;
    @PostMapping("/loginAdmin")
    public RestRequest<User> loginAdmin(@RequestBody User user){
        User u = userService.login(user);
        if(u == null){
            return RestResponse.err("用户不存在或密码不正确");
        } else if (u.getAdmin() == 1) {
            return RestResponse.err("该用户没有管理员权限");
        }else{
            return RestResponse.success("登录成功",u);
        }

    }
    @GetMapping("/getUserList")
    public RestListRequest<User> getUserList(){
        return RestResponse.other(1,"查询成功",userService.getUserList());
    }

}

